//
//  OneLineWithInfoCell.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/5/29.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "OneLineWithInfoCell.h"

@interface OneLineWithInfoCell()

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UILabel *unitLabel;

@end



@implementation OneLineWithInfoCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

/**
 *  <#Description#>
 */
- (void)setupViews {
    self.contentView.width = kScreen_Width;
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CELL_PADDING_LEFT, CELL_PADDING_TOP, kScreen_Width/2 - CELL_PADDING_LEFT, kActionBarFontSize)];
    self.titleLabel.font = [UIFont systemFontOfSize:kActionBarFontSize];
    self.titleLabel.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.titleLabel];
    
    self.infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreen_Width/2 + CELL_PADDING_LEFT, 0, kScreen_Width/2 - 2*CELL_PADDING_LEFT - CELL_PADDING_RIGHT, 14)];
    self.infoLabel.font = [UIFont systemFontOfSize:14];
    self.infoLabel.textColor = BSBlackTextColor1;
    [self.contentView addSubview:self.infoLabel];
    
    self.unitLabel = [[UILabel alloc]initWithFrame:CGRectMake(CELL_PADDING_LEFT, CELL_PADDING_TOP, kScreen_Width/2 - CELL_PADDING_LEFT, kActionBarFontSize)];
    self.unitLabel.font = [UIFont systemFontOfSize:kActionBarFontSize];
    self.unitLabel.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.unitLabel];
    
    self.contentView.height = CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_BOTTOM;
    self.infoLabel.centerY = self.contentView.height/2;
}

- (void)setTitleStr:(NSString*)title andInfoStr:(NSString*)info andInfoAlignment:(NSTextAlignment)alignment{
    self.titleLabel.text = title;
    self.titleLabel.width = [Tools sizeOfSingleLineText:title withSize:kActionBarFontSize].width;
    self.infoLabel.text = info;
    self.infoLabel.width = [Tools sizeOfSingleLineText:info withSize:kActionBarFontSize].width;
    self.infoLabel.textAlignment = alignment;
    self.titleLabel.width = [Tools sizeOfSingleLineText:title withSize:kActionBarFontSize].width;
}

- (void)setTitleStr:(NSString*)title andInfoStr:(NSString*)info andUnitStr:(NSString*)unit{
    self.titleLabel.text = title;
    self.titleLabel.width = [Tools sizeOfSingleLineText:title withSize:kActionBarFontSize].width;
    self.infoLabel.text = info;
    self.infoLabel.width = [Tools sizeOfSingleLineText:info withSize:kActionBarFontSize].width;
    self.unitLabel.text = unit;
    if (![Tools isEmpty:unit]) {
        self.unitLabel.hidden = NO;
        self.unitLabel.width = [Tools sizeOfSingleLineText:unit withSize:kActionBarFontSize].width;
        self.unitLabel.x = kScreen_Width - self.unitLabel.width - CELL_PADDING_RIGHT;
        self.infoLabel.x = self.unitLabel.x - 5 - self.infoLabel.width;
    } else {
        self.unitLabel.hidden = YES;
        self.infoLabel.x = kScreen_Width - self.infoLabel.width - CELL_PADDING_RIGHT;
    }
    
}


- (void)setTitleStr:(NSString*)title andInfoStr:(NSString*)info andInfoColor:(UIColor*)color andInfoAlignment:(NSTextAlignment)alignment {
    self.titleLabel.text = title;
    self.infoLabel.text = info;
//    self.infoLabel.textColor = color;
    self.infoLabel.textAlignment = alignment;
}

- (CGFloat)getHeight {
    return self.contentView.height;
}

@end
